package com.wangsb;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * @Description: TODO
 * @author: shenbing.wang@hand-china
 * @date: 2021年06月20日 16:05
 */
public class Code0305 {


    // 类似于List中toString()方法的实现
    public static void cardDisplay(Map<Integer, String> m, List<Integer> arr, String start) {
        System.out.print(start);
        for(Integer i: arr.subList(0, arr.size()-1)) {
            System.out.print(m.get(i) + ", ");
        }
        System.out.println(m.get(arr.get(arr.size()-1)) + "]");
    }
    public static void main(String[] args) {
        List<String> poker = new ArrayList<>();
        poker.add("大王");
        poker.add("小王");
        String[] flowerColor = {"♠️", "♥️", "♣️", "♦️" };
        String[] cards = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        // 将扑克牌进行组合，组合成54张牌
        for(String c: cards){
            for(String fc: flowerColor) {
                poker.add(fc + c);
            }
        }
        // 给每一张牌编号
        Map<Integer, String> pokerSort = new TreeMap<>();
        for(int i = 1; i <= 54; i++) {
            pokerSort.put(i, poker.get(i-1));
        }
        // 将54张牌打乱
        Set<Integer> keySet =  pokerSort.keySet();
        List<Integer> keys = new ArrayList<>(keySet);
        Collections.shuffle(keys);
        // 创建3个牌友
        List<Integer> WSB = new ArrayList<>();
        List<Integer> Bob = new ArrayList<>();
        List<Integer> JiaJia = new ArrayList<>();
        // 最后3张留作底牌
        List<Integer> safeCards = new ArrayList<>(keys.subList(keys.size() - 3, keys.size()));
        keys.removeAll(safeCards);
        // 创建迭代器开始发牌
        Iterator<Integer> pokerIterator = keys.iterator();
        while(pokerIterator.hasNext()) {
            WSB.add(pokerIterator.next());
            Bob.add(pokerIterator.next());
            JiaJia.add(pokerIterator.next());
        }
        // 看牌
        Collections.sort(safeCards);
        Collections.sort(WSB);
        Collections.sort(Bob);
        Collections.sort(JiaJia);
        Code0305.cardDisplay(pokerSort,safeCards, "底牌:[");
        Code0305.cardDisplay(pokerSort, WSB, "Oliver:[");
        Code0305.cardDisplay(pokerSort, Bob, "Jack:[");
        Code0305.cardDisplay(pokerSort, JiaJia, "Roy:[");
    }


}
